<?php

if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class Login extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		$this->load->model('function_model');
		$this->load->model('MChain');
		// $this->output->enable_profiler(true);
	}

	public function index() {
		$data['title']= 'Main';
		$this->load->view('header',$data);
		$this->load->view("main", $data);
		$this->load->view('footer',$data);
	}
	
	
	public function admin_login()
	{
		if(($this->session->userdata('logged_in')==true))
		{
			$this->welcome();
		}else{
			$data['title']= 'Login';
			$this->load->view('header',$data);
			$this->load->view('login', $data);
			$this->load->view('footer',$data);
		}
		
	}
	
	
	public function admin_login_action()
	{
		$user=$this->input->post('account_user');
		$password=md5($this->input->post('password'));
	
		if(($this->session->userdata('logged_in')==true))
		{
			$this->welcome();
		}elseif($user=="" ||$password==""){
			echo "<script>alert('Please Insert Data');</script>";
			$data['title']= 'Login';
			$this->load->view('header',$data);
			$this->load->view('login', $data);
			$this->load->view('footer',$data);
		}else{
	
			$result=$this->function_model->login($user,$password);
			if($result){
				$this->welcome();
			}else{
				echo "<script>alert('Please Login again');</script>";
				$this->index();
				$this->load->view('footer');
					
					
			}
		}
	}
	
	public function welcome()
	{
		$data['title']= 'Welcome';
		$this->load->view('header',$data);
		$this->load->view('welcome', $data);
		$this->load->view('footer',$data);
	}
	public function logout() {
		$newdata = array (
				'admin_id' => '',
				'admin_name' => '',
				'admin_email' => '',
				'logged_in' => FALSE 
		);
		$this->session->unset_userdata ( $newdata );
	//	$this->session->sess_destroy ();
		$this->index ();
	}
}
?>